package top.ranzhang.controller.admin;


import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.ranzhang.bean.entity.AttendanceRecords;
import top.ranzhang.bean.entity.ParentCommunications;
import top.ranzhang.common.result.Result;
import top.ranzhang.service.IAttendanceRecordsService;
import top.ranzhang.service.IParentCommunicationsService;

import java.util.List;

/**
 * 考勤记录管理
 */
@RestController
@RequestMapping("/admin/attendance-records")
@RequiredArgsConstructor
public class AttendanceRecordsController {


    private final IAttendanceRecordsService attendanceRecordService;

    /**
     * 创建考勤记录
     *
     * @param attendanceRecord
     */
    @PostMapping
    public Result create(@RequestBody AttendanceRecords attendanceRecord) {
        attendanceRecordService.save(attendanceRecord);
        return Result.success();
    }

    /**
     * 获取所有考勤记录
     *
     * @return
     */
    @GetMapping
    public Result getAll() {
        return Result.success(attendanceRecordService.getAll());
    }

    /**
     * 根据ID获取考勤记录
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        return Result.success(attendanceRecordService.getByIds(id));
    }

    /**
     * 更新考勤记录
     *
     * @param id
     * @param attendanceRecord
     */
    @PutMapping("/{id}")
    public Result update(@PathVariable Integer id, @RequestBody AttendanceRecords attendanceRecord) {
        attendanceRecord.setAttendanceId(id);
        attendanceRecordService.update(attendanceRecord);
        return Result.success();
    }

    /**
     * 删除考勤记录
     *
     * @param id
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Long id) {
        attendanceRecordService.delete(id);
        return Result.success();
    }
}
